import Vue from "vue";
import Vuex from "vuex";
import * as site from "@/api/site";
import user from "./user";
import product from "./product";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    menuTree: [], // 左侧菜单项
  },
  getters: {},
  mutations: {
    // 为menuTree赋值
    getMenuTree(state, payload) {
      state.menuTree = payload;
    },
  },
  actions: {
    async getMenuTree({ commit }) {
      // 发起请求 并 将数据传递给 getMenuTree中的payload
      try {
        let { data } = await site.getMenuTree();
        commit("getMenuTree", data);
      } catch (err) {
        console.log(err);
      }
    },
  },
  modules: {
    user,
    product,
  },
});
